//
//  CowClass.cpp
//  Practice12
//
//  Created by 赵世杰 on 2020/8/2.
//  Copyright © 2020 zhaoshijie. All rights reserved.
//

#include "CowClass.hpp"

#include <iostream>

using namespace std;

Cow::Cow()
{
    name[0]='\0';
    strcpy(name, "shijie");
    hobby = new char[1];
    hobby[0] = '\0';
    weight = 60;
    
}


Cow::Cow(const char *nm,const char *ho,double wt)
{

    strcpy(name, nm);
    hobby = new char[strlen(ho)+1];
    strcpy(hobby, ho);
    weight = wt;
    
}


Cow::Cow(const Cow &c)
{
    
    strcpy(name, c.name);
    hobby = new char(strlen(c.hobby)+1);
    weight = c.weight;
    
}


Cow::~Cow()
{
    
    cout << "over name:" << name << endl;
    
    delete [] hobby;
    
}



Cow & Cow::operator=(const Cow &c)
{
    if(this == &c)
    {
        return *this;
    }
    
    delete [] hobby;
    
    
    strcpy(name, c.name);
    hobby = new char[strlen(c.hobby)+1];
    strcpy(hobby, c.hobby);
    weight = c.weight;
    
    return *this;
    
}


void Cow:: ShowCow() const
{
    cout << "name:" << name << " hobby:" << hobby << " weight:" << weight << endl;
}


